import { request } from '@/utils/request/axios';
import { ErrorMessageMode, PageRequest, PageData } from '#/request';
import { UserOutputDtoSimple } from '@/api/identity/admin/user/model';
import { FunctionOutputDtoSimple } from '@/api/authorization/admin/function/model';

/** 管理-用户功能枚举 */
export enum Api {
  /** 读取用户 */
  ReadUsers = '/api/admin/userFunction/readUsers',
  /** 读取用户功能 */
  ReadFunctions = '/api/admin/userFunction/readFunctions',
}

//#region 读取用户信息
/**
 * 读取用户信息
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readUsers(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<UserOutputDtoSimple>>(
    {
      url: Api.ReadUsers,
      params: params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取用户功能信息
/**
 * 读取用户功能信息
 * @param userId 用户ID
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readUserFunctions(
  userId: string | bigint,
  params: PageRequest,
  mode: ErrorMessageMode = 'message',
) {
  return request.post<PageData<FunctionOutputDtoSimple>>(
    {
      url: `${Api.ReadFunctions}?userId=${userId}`,
      params: params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
